import os
from celery import Celery
from celery.schedules import crontab

from tasks.utils import check_due_tasks

# 设置默认的Django设置模块
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "TestTaskManagement.settings")

app = Celery('TestTaskManagement')

# 使用Django的设置文件配置Celery
app.config_from_object('django.conf:settings', namespace='CELERY')

# 自动发现任务
app.autodiscover_tasks()

# 定时任务配置
app.conf.beat_schedule = {
    # 任务到期提醒
    'test_due_tasks_notification': {
        'task': 'tasks.tasks.test_due_tasks_notification',
        'schedule': crontab(hour=15, minute=10),

    },
    # 点餐提醒
    'order_dinner_task': {
        'task': 'tasks.tasks.order_dinner_task',
        'schedule': crontab(hour=15, minute=30),
    },
}

app.conf.timezone = 'Asia/Shanghai'
